package com.abel.roommanager.filter;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.filter.authz.AuthorizationFilter;

public class ClassFilter extends AuthorizationFilter{

	@Override
	protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception {
		// 获取subject
		Subject currentUser=getSubject(request, response);
//		获取配置文件文件信息
		String [] roles= (String[])mappedValue;
//		判断当前用户有无其中一种，只要有直接反回true
		if (roles!=null&&roles.length!=0) {
			for(String role:roles) {
				if(currentUser.hasRole(role)) {
					return true;
				}
			}
		}
		return false;
	}

}
